package com.danielagarza.app.servicios;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class LeerJSON {
	public static String URL_NOTICIAS="http://li530-140.members.linode.com:9003/servicios/noticias";
    public static String URL_TWITTER = "http://api.twitter.com/1/statuses/user_timeline/DanielaGarzaM.json?count=15";
    public static String URL_YOU_TUBE_CHANNEL = "http://www.youtube.com/user/danielagarza2013";
    public static String URL_INSTAGRAM = "http://instagram.com/DanielaGarzaMayagoitia";
    public static String URL_TWITTER_PERSONAL = "https://twitter.com/DanielaGarzaM";
    
	private static String readJSON(InputStream in) {
		String line = "";
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new InputStreamReader(in));
			line = reader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return line;
	}

	public static String leerJSON(String ruta) {
		String json = "";
		try {
			URL url = new URL(ruta);
			HttpURLConnection con = (HttpURLConnection) url.openConnection();
			json = readJSON(con.getInputStream()).toString();
		} catch (Exception e) {
			System.out.println(">>>" + e.getMessage());
		}
		return json;
	}

}
